package com.hyb.controller;


import com.alibaba.fastjson.JSON;
import com.hyb.Vo.CustomerDictionaryVo;
import com.hyb.entity.Customer;
import com.hyb.page.PageReq;
import com.hyb.response.Result;
import com.hyb.service.CustomerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  客户Controller
 * </p>
 *
 * @author hyb
 * @since 2021-12-29
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @RequestMapping(value = "/saveCustomer",method = RequestMethod.POST)
    @ApiOperation("新建客户信息")
    public String saveCustomer(@RequestBody Customer customer){
        customerService.createCustomerInfo(customer);
        return JSON.toJSONString(new Result().setMessage("保存成功").setCode(200));
    }

    @RequestMapping(value = "/loadAllCustome",method = RequestMethod.GET)
    @ApiOperation("加载所有的客户信息")
    public String loadAllCustome(Integer limit, Integer current){
        PageReq customerInfo = customerService.getCustomerInfo(limit, current);
        return JSON.toJSONString(new Result().setCode(200).setMessage("加载成功").setData(customerInfo));
    }

    @RequestMapping(value = "/loadCustomerByCustomerId",method = RequestMethod.GET)
    @ApiOperation("通过客户Id加载客户信息")
    public String loadCustomerByCustomerId(Integer customerId){
        CustomerDictionaryVo customerById = customerService.getCustomerById(customerId);
        return JSON.toJSONString(new Result().setCode(200).setData(customerById).setMessage("加载成功"));
    }

    @RequestMapping(value = "/updateCustomer",method = RequestMethod.PUT)
    @ApiOperation("修改客户信息")
    public String updateCustomer(@RequestBody Customer customer){
        customerService.updateCustomer(customer);
        return JSON.toJSONString(new Result().setMessage("修改成功").setCode(200));
    }

    @RequestMapping(value = "/getDrainCustomers",method = RequestMethod.GET)
    @ApiOperation("获取客户流失信息")
    public String getDrainCustomers(Integer limit, Integer current, String customerName, String customerState,Integer staffId){
        PageReq drainCustomers = customerService.getDrainCustomers(limit, current, customerName, customerState, staffId);
        return JSON.toJSONString(new Result().setData(drainCustomers).setMessage("加载成功").setCode(200));
    }

    @RequestMapping(value = "/getToBeConfirmedCustomerNum",method = RequestMethod.GET)
    @ApiOperation("获取状态为待确认的客户的数量")
    public String getToBeConfirmedCustomerNum(Integer staffId){
        Integer toBeConfirmedCustomerNum = customerService.getToBeConfirmedCustomerNum(staffId);
        return JSON.toJSONString(new Result().setCode(200).setMessage("加载成功").setData(toBeConfirmedCustomerNum));
    }
}
